console.log("预加载脚本");

const { ipcRenderer,contextBridge } =  require("electron")

contextBridge.exposeInMainWorld('myapi',{
    openfile:async ()=>{
        try{
            // 通过 IPC 调用主进程的对话框
            const filePath = await ipcRenderer.invoke('open-file-dialog');
            
            if (!filePath) {
              resultPath.textContent = '用户取消了选择';
              return;
            }
            
            // 获取文件夹路径
            const folderPath = await ipcRenderer.invoke('get-folder-path', filePath);
            
            resultPath.textContent = folderPath;
            
        } catch (error) {
            console.error('Error:', error);
            resultPath.textContent = '错误: ' + error.message;
        }
    },
    download: async()=>{
       await ipcRenderer.invoke('downloadAndUnzip')
    }
})